<template>
  <view class="flex-col page">
    <view class="flex-col group">
      <view class="flex-col section_1">
        <text class="text_2">评价内容</text>
        <view class="flex-row group_1" style="flex-wrap: wrap">
          <view
            class="flex-col items-center text-wrapper"
            v-for="(item, index) in typeList"
            :class="{ active: item.active }"
            @click="choice(index, item.id)"
            style="margin-top: 10rpx"
          >
            <text>{{ item.name }}</text>
          </view>
        </view>
      </view>
      <view class="flex-col section_2">
        <view class="flex-col">
          <text class="text_7">服务评分</text>
          <u-rate
            :count="count"
            v-model="service_score"
            active-color="rgb(24, 182, 103)"
            size="30"
            >服务评分
          </u-rate>
        </view>
        <view class="flex-col" style="padding-top: 30rpx">
          <text class="text_7">技师评分</text>
          <u-rate
            :count="count"
            v-model="technician_score"
            active-color="rgb(24, 182, 103)"
            size="30"
            >技师评分
          </u-rate>
        </view>
      </view>
      <view class="flex-col section_1">
        <view class="group_1">
          <input
            style="width: 100%"
            v-model="content"
            placeholder="请输入补充内容(选填)"
            class="text-wrapper"
          />
        </view>
      </view>
      <view class="flex-col section_3">
        <!-- <view class="flex-col">
					<text class="text_9">联系方式</text>
					<text class="text_10">
					 <u--input
						type="number"
					    placeholder="留下您的联系方式方便我们联系您哦~"
					    v-model="mobile"
						border="none"
					  ></u--input></text>
				</view> -->
        <view class="flex-col items-center button" @tap.stop="submit">
          <text>提交评价</text>
        </view>

        <!-- <view class="submit" @click="toPath">查看反馈记录</view> -->
      </view>
    </view>
  </view>
</template>

<script>
import { uploadImage } from "@/config/utils";
export default {
  data() {
    return {
      selectValue: [],
      selectItem: [],
      content: "",
      mobile: "",
      typeList: [],
      images: [],
      order_sn: "",
      service_score: 0,
      technician_score: 0,
      count: 5,
    };
  },
  onLoad(e) {
    this.order_sn = e.order_sn;
    this.init();
  },
  methods: {
    upload() {
      uni.chooseImage({
        count: 1,
        success: (res) => {
          uni.showLoading({
            title: "图片上传中",
          });
          let { tempFilePaths } = res;
          let file = tempFilePaths[0];
          uploadImage(file).then((res) => {
            uni.hideLoading();
            this.images.push(res);
          });
        },
      });
    },
    del(index) {
      uni.showModal({
        content: "是否确认删除此图片",
        success: (res) => {
          let { confirm } = res;
          if (confirm) {
            this.images.splice(index, 1);
          }
        },
      });
    },
    init() {
      // 获取意见反馈类型
      this.$http.post("api/order/commentType").then((res) => {
        this.typeList = res;
        for (let i = 0; i < this.typeList.length; i++) {
          this.typeList[i].active = false;
        }
      });
    },
    choice(e, item) {
      if (this.selectValue.includes(e)) {
        this.typeList[e].active = false;
        var index0 = this.selectValue.findIndex((item) => {
          if (item == e) {
            return true;
          }
        });
        this.selectValue.splice(index0, 1);
        this.selectItem.splice(index0, 1);
      } else {
        this.typeList[e].active = true;
        this.selectValue.push(e);
        this.selectItem.push(item);
      }
      this.typeList = [...this.typeList];
    },
    toPath() {
      uni.navigateTo({
        url: "/bundle/pages/feedback_record/feedback_record",
      });
    },
    submit() {
      if (this.selectItem.length < 1) {
        uni.showToast({
          icon: "none",
          title: "请选择评价内容",
        });
        return;
      }

      if (!this.service_score) {
        uni.showToast({
          icon: "none",
          title: "请对服务评分",
        });
        return;
      }
      if (!this.technician_score) {
        uni.showToast({
          icon: "none",
          title: "请对技师评分",
        });
        return;
      }
      let sendData = {
        types: this.selectItem.join(","),
        service_score: this.service_score,
        technician_score: this.technician_score,
        order_sn: this.order_sn,
      };
      if (this.content) {
        sendData.content = this.content;
      }

      this.$http.post("api/order/comment", sendData).then((res) => {
        uni.showToast({
          icon: "success",
          title: "评价成功",
        });
        setTimeout(function () {
          uni.switchTab({
            url: "/pages/order/order",
          });
        }, 1000);
      });
    },
  },
};
</script>

<style scoped lang="scss">
.page {
  background-color: #f8f8f8;
  width: 100%;
  height: 100%;
  overflow-y: auto;

  .group {
    flex: 1 1 auto;
    overflow-y: auto;

    .section_1 {
      padding: 42rpx 32rpx 40rpx;
      background-color: rgb(255, 255, 255);

      .text_2 {
        color: rgb(0, 0, 0);
        font-size: 32rpx;
        font-weight: 500;
        line-height: 44rpx;
        white-space: nowrap;
      }

      .group_1 {
        margin-top: 32rpx;

        .text-wrapper {
          padding: 10rpx;
          width: 200rpx;
          margin-right: 10rpx;

          font-size: 28rpx;
          line-height: 40rpx;
          white-space: nowrap;

          border-radius: 12rpx;
          height: 64rpx;

          color: rgb(153, 153, 153);
          background-color: rgb(244, 244, 244);

          border: none;

          &.active {
            color: rgb(24, 182, 103);
            border: solid 2rpx rgb(24, 181, 103);
            background-color: rgba(24, 181, 103, 0.18);
          }
        }

        .text-wrapper_1 {
          margin-left: 25rpx;
          flex: 1 1 154rpx;
          color: rgb(153, 153, 153);
          font-size: 28rpx;
          line-height: 40rpx;
          white-space: nowrap;
          padding: 12rpx 0;
          background-color: rgb(244, 244, 244);
          border-radius: 12rpx;
          height: 64rpx;
        }

        .view_1 {
          margin-left: 23rpx;
        }
      }
    }

    .section_2 {
      padding: 40rpx 32rpx;
      background-color: rgb(255, 255, 255);

      .group_3 {
        padding: 78rpx 0;
        position: relative;
        width: 100%;
        display: flex;
        flex-wrap: wrap;

        .image {
          position: relative;
          width: 212rpx;
          height: 212rpx;
          flex-shrink: 0;
          display: flex;
          align-items: center;
          justify-content: center;
          margin: 0 30rpx 20rpx 0;

          .close {
            width: 40rpx;
            height: 40rpx;
            position: absolute;
            top: -20rpx;
            right: -20rpx;
          }
        }

        .image_1 {
          width: 56rpx;
          height: 56rpx;
        }

        .image_2 {
          border-radius: 24rpx;
          width: 212rpx;
          height: 212rpx;
          position: absolute;
          left: 0;
          bottom: 0;
        }
      }

      .text_7 {
        color: rgb(0, 0, 0);
        font-size: 32rpx;
        font-weight: 500;
        line-height: 44rpx;
        white-space: nowrap;
      }

      .text_8 {
        margin-top: 28rpx;
        color: rgb(153, 153, 153);
        font-size: 28rpx;
        line-height: 40rpx;
        white-space: nowrap;
      }
    }

    .section_3 {
      padding: 40rpx 32rpx 100rpx;
      background-color: rgb(255, 255, 255);

      .button {
        margin-top: 84rpx;
        padding: 26rpx 0;
        color: rgb(255, 255, 255);
        font-size: 32rpx;
        font-weight: 500;
        line-height: 44rpx;
        white-space: nowrap;
        background-color: rgb(24, 181, 103);
        border-radius: 48rpx;
      }

      .text_9 {
        color: rgb(0, 0, 0);
        font-size: 32rpx;
        font-weight: 500;
        line-height: 44rpx;
        white-space: nowrap;
      }

      .text_10 {
        margin-top: 28rpx;
        color: rgb(153, 153, 153);
        font-size: 28rpx;
        line-height: 40rpx;
        white-space: nowrap;
      }
    }
  }

  .submit {
    text-align: center;
    color: rgba(70, 209, 126, 1);
    font-size: 28rpx;
    padding: 40rpx 0;
  }
}
</style>
